Vue.component('update', {
    template: `
		<el-dialog title="修改" width="900px" class="icon-dialog" :visible.sync="show" @open="open" :before-close="closeForm" append-to-body>
			<el-form :size="size" ref="form" :model="form" :rules="rules" :label-width=" ismobile()?'90px':'16%'">
              <el-row >
                <el-col :span="24">
                  <el-form-item label="矿机名称" prop="name">
                    <el-input  v-model="form.name" autoComplete="off" clearable placeholder="简体"></el-input>

                    <el-input  v-model="form.t_name" autoComplete="off" clearable placeholder="繁体"></el-input>

                    <el-input  v-model="form.e_name" autoComplete="off" clearable placeholder="英文"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row v-if="form.type == 1">
                <el-col :span="24">
                  <el-form-item label="购买支付币种:">
                    <el-radio-group v-model="form.currency">
                      <el-radio :label="1">USDT</el-radio>
                      <el-radio :label="2">MMST</el-radio>
                    </el-radio-group>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="24" >
                  <el-form-item label="矿机总量" prop="total_num">
                    <el-input typt="number" v-model="form.total_num" autoComplete="off" filterable clearable placeholder="请输入数量"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="24" >
                  <el-form-item label="产出销毁比例(%)" prop="destruction_ratio">
                    <el-input typt="number" v-model="form.destruction_ratio" autoComplete="off" filterable clearable placeholder="请输入数量"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="24" >
                  <el-form-item label="虚拟总销毁数量" prop="virtual_destruction">
                    <el-input typt="number" v-model="form.virtual_destruction" autoComplete="off" filterable clearable placeholder="请输入数量"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row >
                <el-col :span="24">
                  <el-form-item label="虚拟已释放数量" prop="virtual_release">
                    <el-input typt="number" v-model="form.virtual_release" autoComplete="off" filterable clearable placeholder="请输入数量"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row >
					<el-col :span="24">
						<el-form-item label="设备编号" prop="equipment">
							<el-input v-model="form.equipment" autoComplete="off" filterable clearable placeholder="请输入设备编号"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="芯片代码" prop="chip">
							<el-input typt="number" v-model="form.chip" autoComplete="off" filterable clearable placeholder="请输入芯片代码"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
              <el-row >
                <el-col :span="24">
                  <el-form-item label="矿机状态:">
                    <el-radio-group v-model="form.status">
                      <el-radio :label="1">开启</el-radio>
                      <el-radio :label="2">关闭</el-radio>
                      <el-radio :label="3">已释放完毕</el-radio>
                    </el-radio-group>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row >
                <el-col :span="24">
                    <el-form-item label="释放方式:">
                        <el-radio-group v-model="form.release_mode">
                            <el-radio :label="1">独立释放</el-radio>
                            <el-radio :label="2">全网按个人占比释放</el-radio>
                        </el-radio-group>
                    </el-form-item>
                </el-col>
			  </el-row>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button :size="size" :loading="loading" type="primary" @click="submit" >
					<span v-if="!loading">确 定</span>
					<span v-else>提 交 中...</span>
				</el-button>
				<el-button :size="size" @click="closeForm">取 消</el-button>
			</div>
		</el-dialog>
	`,
    components:{
    },
    props: {
        show: {
            type: Boolean,
            default: false
        },
        size: {
            type: String,
            default: 'small'
        },
        info: {
            type: Object,
        },
    },
    data(){
        return {
            form: {
                id:'',
                name:'',
                e_name:'',
                t_name:'',
                currency:1,
                total_num:'',
                virtual_destruction:0,
                virtual_release:0,
                status:1,
                destruction_ratio:0,
                chip:'',
                equipment:'',
                release_mode:1,
            },
            loading:false,
            rules: {
                name:[
                    {required: true, message: '矿机名称不能为空', trigger: 'blur'},
                ],
                e_name:[
                    {required: true, message: '矿机名称不能为空', trigger: 'blur'},
                ],
                t_name:[
                    {required: true, message: '矿机名称不能为空', trigger: 'blur'},
                ],
                total_num:[
                    {required: true, message: '请输入矿机释放总量', trigger: 'blur'},
                ],
                everyday_num:[
                    {required: true, message: '请输入矿机每日释放数量', trigger: 'blur'},
                ],
                status:[
                    {required: true, message: '请选择矿机状态', trigger: 'blur'},
                ],
            }
        }
    },
    methods: {
        open(){
            this.form = this.info
        },
        submit(){
            this.$refs['form'].validate(valid => {
                if(valid) {
                    this.loading = true
                    axios.post(base_url + '/Mining/edit',this.form).then(res => {
                        if(res.data.status == 200){
                            this.$message({message: res.data.msg, type: 'success'})
                            this.$emit('refesh_list')
                            this.closeForm()
                        }else{
                            this.loading = false
                            this.$message.error(res.data.msg)
                        }
                    }).catch(()=>{
                        this.loading = false
                    })
                }
            })
        },
        closeForm(){
            this.$emit('update:show', false)
            this.loading = false
            if (this.$refs['form']!==undefined) {
                this.$refs['form'].resetFields()
            }
        },
    }
})
